This is a demo that we’re showing at Summit18:
- Send an SMS or MMS to 1-415-792-4932
- It’ll show up on https://jsfiddle.net/eurica/zwyeatL1/embedded/result
I used 2 parts of the API, a Custom Event Transformer and ourREST API for Incidents.
The Custom Event Transformer is pretty easy, take the JSON that we get from Twilio, and if there’s a picture, send it along as a context.
var contexts = [];
if (PD.inputRequest.body.MediaUrl0) {
contexts.push({
"type": "image",
"src": PD.inputRequest.body.MediaUrl0
});
PD.inputRequest.body.Body = "Picture"
}
var normalized_event = {
incident_key: PD.inputRequest.body.SmsMessageSid,
event_type: PD.Trigger,
description: "SMS received: " + PD.inputRequest.body.Body,
contexts: contexts
};
PD.emitGenericEvents([normalized_event]);
The page that displays the images & texts is a little sloppier (this is just a demo!). You can fork my demo code on jsfiddle: https://jsfiddle.net/eurica/zwyeatL1/ (don’t forget to change the service_ids)
$.ajax({
dataType: "json",
url: "https://api.pagerduty.com/incidents?statuses%5B%5D=triggered" +
"&statuses%5B%5D=acknowledged&" +
"service_ids%5B%5D=PK01EFR" +
"&time_zone=UTC" +
"&include%5B%5D=first_trigger_log_entries" +
"&sort_by=created_at",
headers: {
"Accept": "application/vnd.pagerduty+json;version=2",
"Authorization": "Token token=u9M7RTpKMPNAbb8yEyYu"
},
success: function(data) {
//Update the screen
}
});